<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="Corpid" prop="corpid">
        <el-input
          v-model="queryParams.corpid"
          placeholder="请输入Corpid"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="corpName">
        <el-input
          v-model="queryParams.corpName"
          placeholder="请输入名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="Logo" prop="corpSquareLogoUrl">
        <el-input
          v-model="queryParams.corpSquareLogoUrl"
          placeholder="请输入Logo"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户规模" prop="corpUserMax">
        <el-input
          v-model="queryParams.corpUserMax"
          placeholder="请输入用户规模"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="AgentMax" prop="corpAgentMax">
        <el-input
          v-model="queryParams.corpAgentMax"
          placeholder="请输入AgentMax"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="二维码" prop="corpWxqrcode">
        <el-input
          v-model="queryParams.corpWxqrcode"
          placeholder="请输入二维码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规模" prop="corpScale">
        <el-input
          v-model="queryParams.corpScale"
          placeholder="请输入规模"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属行业" prop="corpIndustry">
        <el-input
          v-model="queryParams.corpIndustry"
          placeholder="请输入所属行业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属子行业" prop="corpSubIndustry">
        <el-input
          v-model="queryParams.corpSubIndustry"
          placeholder="请输入所属子行业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在地信息" prop="location">
        <el-input
          v-model="queryParams.location"
          placeholder="请输入所在地信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员等级" prop="vipLevel">
        <el-input
          v-model="queryParams.vipLevel"
          placeholder="请输入会员等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除时间" prop="deletedAt">
        <el-date-picker clearable
                        v-model="queryParams.deletedAt"
                        type="date"
                        value-format="yyyy-MM-dd"

                        placeholder="请选择删除时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="新增时间" prop="createdAt">
        <el-date-picker clearable
                        v-model="queryParams.createdAt"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择新增时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updatedAt">
        <el-date-picker clearable
                        v-model="queryParams.updatedAt"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="3" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:corp_companies:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:corp_companies:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:corp_companies:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:corp_companies:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :stripe="true" :data="corp_companiesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="45" align="center"/>
      <el-table-column label="ID" align="center" width="50" prop="id"/>
      <el-table-column label="Corpid" align="center" width="170" prop="corpid" v-if="columns[0].visible"/>
      <el-table-column label="名称" align="center" width="150" prop="corpName" v-if="columns[1].visible"/>
      <el-table-column label="类型" align="center" width="90" prop="corpType" v-if="columns[2].visible"/>
      <el-table-column label="用户规模" align="center" prop="corpUserMax" v-if="columns[3].visible"/>
      <el-table-column label="AgentMax" align="center" width="90" prop="corpAgentMax" v-if="columns[4].visible"/>
      <el-table-column label="类型" align="center" prop="subjectType" v-if="columns[5].visible"/>
      <el-table-column label="规模" align="center" width="95" prop="corpScale" v-if="columns[6].visible"/>
      <el-table-column label="所属行业" align="center" width="100" prop="corpIndustry" v-if="columns[7].visible"/>
      <el-table-column label="所属子行业" align="center" width="150" :show-overflow-tooltip="true" prop="corpSubIndustry" v-if="columns[8].visible"/>
      <el-table-column label="所在地信息" align="center" width="150" :show-overflow-tooltip="true" prop="location" v-if="columns[9].visible"/>
      <el-table-column label="会员等级" align="center" prop="vipLevel" v-if="columns[10].visible"/>
      <el-table-column label="状态" align="center" prop="status" v-if="columns[11].visible"/>
      <el-table-column label="Logo" align="center" width="300" :show-overflow-tooltip="true" prop="corpSquareLogoUrl" v-if="columns[12].visible"/>
      <el-table-column label="二维码" align="center" width="300" :show-overflow-tooltip="true" prop="corpWxqrcode" v-if="columns[13].visible"/>
      <el-table-column label="新增时间" align="center" width="100" prop="createdAt" v-if="columns[14].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" width="100" prop="updatedAt" v-if="columns[15].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right" width="110px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:corp_companies:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:corp_companies:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改宝企通-企业管理后台-合作企业对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="Corpid" prop="corpid">
          <el-input v-model="form.corpid" placeholder="请输入Corpid"/>
        </el-form-item>
        <el-form-item label="名称" prop="corpName">
          <el-input v-model="form.corpName" placeholder="请输入名称"/>
        </el-form-item>
        <el-form-item label="Logo" prop="corpSquareLogoUrl">
          <el-input v-model="form.corpSquareLogoUrl" placeholder="请输入Logo"/>
        </el-form-item>
        <el-form-item label="用户规模" prop="corpUserMax">
          <el-input v-model="form.corpUserMax" placeholder="请输入用户规模"/>
        </el-form-item>
        <el-form-item label="AgentMax" prop="corpAgentMax">
          <el-input v-model="form.corpAgentMax" placeholder="请输入AgentMax"/>
        </el-form-item>
        <el-form-item label="二维码" prop="corpWxqrcode">
          <el-input v-model="form.corpWxqrcode" placeholder="请输入二维码"/>
        </el-form-item>
        <el-form-item label="规模" prop="corpScale">
          <el-input v-model="form.corpScale" placeholder="请输入规模"/>
        </el-form-item>
        <el-form-item label="所属行业" prop="corpIndustry">
          <el-input v-model="form.corpIndustry" placeholder="请输入所属行业"/>
        </el-form-item>
        <el-form-item label="所属子行业" prop="corpSubIndustry">
          <el-input v-model="form.corpSubIndustry" placeholder="请输入所属子行业"/>
        </el-form-item>
        <el-form-item label="所在地信息" prop="location">
          <el-input v-model="form.location" placeholder="请输入所在地信息"/>
        </el-form-item>
        <el-form-item label="会员等级" prop="vipLevel">
          <el-input v-model="form.vipLevel" placeholder="请输入会员等级"/>
        </el-form-item>
        <el-form-item label="删除时间" prop="deletedAt">
          <el-date-picker clearable
                          v-model="form.deletedAt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择删除时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="新增时间" prop="createdAt">
          <el-date-picker clearable
                          v-model="form.createdAt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择新增时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updatedAt">
          <el-date-picker clearable
                          v-model="form.updatedAt"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addCorp_companies,
  delCorp_companies,
  getCorp_companies,
  listCorp_companies,
  updateCorp_companies
} from "@/api/admin/corp_companies";

export default {
  name: "Corp_companies",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 宝企通-企业管理后台-合作企业表格数据
      corp_companiesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        corpid: null,
        corpName: null,
        corpType: null,
        corpSquareLogoUrl: null,
        corpUserMax: null,
        corpAgentMax: null,
        corpWxqrcode: null,
        subjectType: null,
        corpScale: null,
        corpIndustry: null,
        corpSubIndustry: null,
        location: null,
        vipLevel: null,
        status: null,
        deletedAt: null,
        createdAt: null,
        updatedAt: null
      },
      // 表单参数
      form: {},
      // 显示的列
      columns: [
        { key: 0, label: `Corpid`, visible: true },
        { key: 1, label: `名称`, visible: true },
        { key: 2, label: `类型`, visible: true },
        { key: 3, label: `用户规模`, visible: true },
        { key: 4, label: `AgentMax`, visible: true },
        { key: 5, label: `规模`, visible: true },
        { key: 6, label: `类型`, visible: true },
        { key: 7, label: `所属行业`, visible: true },
        { key: 8, label: `所属子行业`, visible: true },
        { key: 9, label: `所在地信息`, visible: true },
        { key: 10, label: `会员等级`, visible: true },
        { key: 11, label: `状态`, visible: true },
        { key: 12, label: `Logo`, visible: true },
        { key: 13, label: `二维码`, visible: true },
        { key: 14, label: `新增时间`, visible: true },
        { key: 15, label: `更新时间`, visible: true }
      ],
      // 表单校验
      rules: {
        corpid: [
          {required: true, message: "Corpid不能为空", trigger: "blur"}
        ],
        corpName: [
          {required: true, message: "名称不能为空", trigger: "blur"}
        ],
        corpType: [
          {required: true, message: "类型不能为空", trigger: "change"}
        ],
        corpSquareLogoUrl: [
          {required: true, message: "Logo不能为空", trigger: "blur"}
        ],
        corpUserMax: [
          {required: true, message: "用户规模不能为空", trigger: "blur"}
        ],
        corpAgentMax: [
          {required: true, message: "AgentMax不能为空", trigger: "blur"}
        ],
        corpWxqrcode: [
          {required: true, message: "二维码不能为空", trigger: "blur"}
        ],
        subjectType: [
          {required: true, message: "类型不能为空", trigger: "change"}
        ],
        corpScale: [
          {required: true, message: "规模不能为空", trigger: "blur"}
        ],
        corpIndustry: [
          {required: true, message: "所属行业不能为空", trigger: "blur"}
        ],
        corpSubIndustry: [
          {required: true, message: "所属子行业不能为空", trigger: "blur"}
        ],
        location: [
          {required: true, message: "所在地信息不能为空", trigger: "blur"}
        ],
        vipLevel: [
          {required: true, message: "会员等级不能为空", trigger: "blur"}
        ],
        status: [
          {required: true, message: "状态不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询宝企通-企业管理后台-合作企业列表 */
    getList() {
      this.loading = true;
      listCorp_companies(this.queryParams).then(response => {
        this.corp_companiesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        corpid: null,
        corpName: null,
        corpType: null,
        corpSquareLogoUrl: null,
        corpUserMax: null,
        corpAgentMax: null,
        corpWxqrcode: null,
        subjectType: null,
        corpScale: null,
        corpIndustry: null,
        corpSubIndustry: null,
        location: null,
        vipLevel: null,
        status: 0,
        deletedAt: null,
        createdAt: null,
        updatedAt: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加宝企通-企业管理后台-合作企业";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCorp_companies(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改宝企通-企业管理后台-合作企业";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCorp_companies(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCorp_companies(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除宝企通-企业管理后台-合作企业编号为"' + ids + '"的数据项？').then(function () {
        return delCorp_companies(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/corp_companies/export', {
        ...this.queryParams
      }, `corp_companies_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped>
.el-form-item--small.el-form-item{
  margin-bottom: 10px;
}
/deep/ label{
  font-weight: 500;
}
/deep/ .el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 215px;
}
</style>
